package com.itheima.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * 执行 insert 语句
 *      释放资源的语句写在 finally 中
 */
public class JdbcDemo2 {
    public static void main(String[] args) throws Exception{
        Connection connection = null;
        Statement statement = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver") ;

            //获取连接对象
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tlias", "root", "204020");
            //sql
            String sql = "insert into dept (name , create_time , update_time) values ('通关不' , now() , now())";
            //执行对象
            statement = connection.createStatement();
            //执行sql
            int count = statement.executeUpdate(sql);
            //处理结果
            if (count > 0){
                System.out.println("添加成功");
            }else {
                System.out.println("添加失败");
            }

        } finally {
            //释放资源
            statement.close();
            connection.close();
        }
    }
}
